if(typeof Ext.user.method.binzhongidstore == 'undefined'){ Ext.user.method.binzhongidstore = Ext.user.method.binzhongid(); }
Ext.user.binzhongtree = Ext.extend(Ext.tree.TreePanel, {
    title: '病种管理',
	id:'binzhongtree',
    width: 700,
    height: 600,
	style:'margin:0 auto;',
	renderTo:'binzhong_index',
    initComponent: function() {
        this.root = {
            text: '病种库',
            id: 'menu'
        };
        this.loader = {
            url: Ext.user.baseUrl + '/Binzhong/data/',
            nodeParameter: 'p',
			baseParams:{do:'p'}
        };
		this.tbar = [{text: '添加病例',iconCls: 'page_add',
			handler:function(){
				var binzhong = new Ext.user.binzhongWindows();
				binzhong.show();
			
			},
		}];
		this.listeners= {
			click:function(n,e){
				if(n.attributes.id !== 'menu'){
					var binzhong = new Ext.user.binzhongWindows({edit:{id:n.attributes.id}});
					binzhong.show();
					binzhong.setTitle('修改病种信息');
					
					
					Ext.user.method.loaddataForm({
						url:'/Binzhong/data/',
						params:{where:n.attributes.id,do:'binzhongid'},
						Formid:'binzhongForm',
						method:'POST',
						recorddata:[{name: 'name', type: 'string'}, 'did','sort','tel','intro']
					});
					Ext.getCmp('binzhongForm').add(new Ext.form.Hidden({name:'id',value:n.attributes.id,renderTo:'binzhongFormid'}));
				}
			},
	
		};
        Ext.user.binzhongtree.superclass.initComponent.call(this);
    }
});
Ext.user.binzhongWindows = Ext.extend(Ext.Window, {
    title: '添加病种信息',
    width: 500,
    border: false,
    frame: true,
	modal:true,
	id:'binzhongtreeWindow',
	modal:true,
	listeners:{
		close:function(a){
				Ext.user.centermenu.setDisabled(false);
			  }
	},
    initComponent: function(cfg) {
		this.cfg = cfg || {};
		Ext.apply(this,this.cfg);
        this.items = [
            {
                xtype: 'form',
				id:'binzhongForm',
				formId:'binzhongFormid',
                border: false,
                items: [
                    {
                        xtype: 'fieldset',
                        title: '必填信息',
                        style: 'margin: 0 auto;',
                        width: 480,
                        items: [
							{	
								xtype: 'combo',
								fieldLabel: '上一级',
								anchor: '50%',
								name:'pid', 
								store: Ext.user.method.binzhongidstore,
								displayField:'name',
								valueField:'id',
								hiddenName:'pid',
								hiddenValue:'0',
								editable:false,
								typeAhead: true,
								forceSelection: true,
								mode: 'local',
								triggerAction: 'all',
								emptyText:'无上一级',
								selectOnFocus:true,
								
								
							},
                           {
                                xtype: 'textfield',
                                fieldLabel: '病种名称',
                                anchor: '50%',
                                width: 300,
                                name: 'name'
                            },
                            {
                                xtype: 'textfield',
                                fieldLabel: '排序',
                                anchor: '50%',
                                width: 300,
                                name: 'sort',
                                value: 0
                            },
                        ]
                    }
                ]
            }
        ];
		if(typeof this.edit == 'undefined'){
			this.buttons = [{text:'添加',
				handler:function(){
					Ext.getCmp('binzhongForm').form.submit({
						method: 'POST',
						url:Ext.user.baseUrl + '/Binzhong/add',
						waitMsg: '正在提交。。。',
						success:function(f,a){
							Ext.MessageBox.show({
								 title: '警告',
								 msg: a.result.info,
								 buttons: Ext.MessageBox.OK,
								 icon:'ext-mb-info',
							});
							Ext.getCmp('binzhongtree').root.reload();
							Ext.getCmp('binzhongtreeWindow').close();
						},
						failure:function(f,a){
								Ext.MessageBox.show({
									 title: '警告',
									 msg: a.result.info,
									 buttons: Ext.MessageBox.OK,
										 icon:'ext-mb-error',
								});	
						}
					});
				}
			},{text:'重置',
				handler:function(){
					Ext.getCmp('departmentForm').form.reset();
				}
			}];
		}else{
			this.buttons = [{text:'修改',
				handler:function(){
					Ext.getCmp('binzhongForm').form.submit({
						method: 'POST',
						url:Ext.user.baseUrl + '/Binzhong/edit/',
						waitMsg: '正在提交。。。',
						success:function(f,a){
							Ext.MessageBox.show({
								 title: '警告',
								 msg: a.result.info,
								 buttons: Ext.MessageBox.OK,
								 icon:'ext-mb-info',
							});
							Ext.getCmp('binzhongtree').root.reload();
							Ext.getCmp('binzhongtreeWindow').close();
						},
						failure:function(f,a){
								Ext.MessageBox.show({
									 title: '警告',
									 msg: a.result.info,
									 buttons: Ext.MessageBox.OK,
										 icon:'ext-mb-error',
								});	
						}
					});
				}
			},{text:'删除',
				handler:function(){
					Ext.Ajax.request({
					   url: Ext.user.baseUrl + '/Binzhong/delete',
					   method:'POST',
					   callback:function(o,s,r){
							var data = Ext.util.JSON.decode(r.responseText);
							Ext.MessageBox.show({
								 title: '警告',
								 msg: data.info,
								 buttons: Ext.MessageBox.OK,
								 icon:'ext-mb-info',
							});
						
							Ext.getCmp('binzhongtree').root.reload();
					   },
					   params: {id:Ext.getCmp('binzhongtreeWindow').edit.id}
					});
					Ext.getCmp('binzhongtreeWindow').close();
				}
			}];		
		
		}
        Ext.user.binzhongWindows.superclass.initComponent.call(this);
    }
});





